<template>
  <view class="announcement-section" v-if="announcements.length > 0">
    <view class="announcement-banner">
      <view class="banner-content">
        <text class="banner-icon">📢</text>
        <swiper 
          class="announcement-swiper" 
          :autoplay="true" 
          :interval="6000" 
          :duration="800"
          :circular="true"
          :indicator-dots="false"
          @change="handleSwiperChange"
        >
          <swiper-item v-for="(announcement, index) in announcements" :key="index">
            <view class="announcement-item" @click="handleAnnouncementClick(announcement)">
              <text class="announcement-text">{{ announcement.title }}</text>
              <text class="announcement-arrow">></text>
            </view>
          </swiper-item>
        </swiper>
      </view>
    </view>
    
    <!-- 自定义指示点 -->
    <view class="announcement-indicators">
      <view 
        v-for="(announcement, index) in announcements" 
        :key="index"
        class="indicator-dot"
        :class="{ 'active': currentIndex === index }"
        @click="switchToAnnouncement(index)"
      ></view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'AnnouncementBanner',
  props: {
    announcements: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    handleSwiperChange(e) {
      this.currentIndex = e.detail.current
      this.$emit('index-change', this.currentIndex)
    },
    handleAnnouncementClick(announcement) {
      this.$emit('announcement-click', announcement)
    },
    switchToAnnouncement(index) {
      this.currentIndex = index
      this.$emit('switch-to', index)
    }
  }
}
</script>

<style scoped>
/* 公告区域 */
.announcement-section {
  margin-bottom: 24rpx;
}

.announcement-banner {
  background: white;
  border-radius: 20rpx;
  padding: 20rpx 24rpx;
  box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.08); }
  50% { box-shadow: 0 8rpx 24rpx rgba(102, 126, 234, 0.12); }
}

.banner-content {
  display: flex;
  align-items: center;
  gap: 16rpx;
}

.banner-icon {
  font-size: 32rpx;
  animation: bell-ring 2s ease-in-out infinite;
}

@keyframes bell-ring {
  0%, 100% { transform: rotate(0deg); }
  10%, 30% { transform: rotate(-10deg); }
  20%, 40% { transform: rotate(10deg); }
  50%, 100% { transform: rotate(0deg); }
}

.announcement-swiper {
  flex: 1;
  height: 48rpx;
}

.announcement-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 8rpx;
}

.announcement-text {
  flex: 1;
  font-size: 24rpx;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.announcement-arrow {
  font-size: 24rpx;
  color: #9ca3af;
  margin-left: 12rpx;
}

.announcement-indicators {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12rpx;
  padding-top: 16rpx;
}

.indicator-dot {
  width: 16rpx;
  height: 16rpx;
  border-radius: 50%;
  background: #d1d5db;
  transition: all 0.3s ease;
  cursor: pointer;
}

.indicator-dot.active {
  width: 32rpx;
  border-radius: 8rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
</style>

